/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2014-2019.
 * Description: init idump for rtos_mm_struct extend
 * Author: nixiaoming
 * Create: 2014-6-18
 */
#ifndef _FS_IDUMP_C_
#define _FS_IDUMP_C_
#include <linux/idump.h>
#include <linux/task_struct_extend.h>
#include <linux/idump_mm_extend.h>

void init_idump_mm_extend(struct idump_mm_extend *idump_mm)
{
	struct rtos_mm_struct *rtos_mm_current = NULL;
#if defined(CONFIG_RTOS_IDUMP_FORCE) || defined(CONFIG_RTOS_IDUMP_TRIGGER)
	idump_mm->core_state = NULL;
	/* Initialization of idump timeout */
	idump_mm->timeout_msec = 1000;
#endif

	if (current->mm != NULL) {
		rtos_mm_current = mm_to_rtos_mm(current->mm);
		idump_mm->stacksize = rtos_mm_current->idump.stacksize;
		idump_mm->dump_filter_type = rtos_mm_current->idump.dump_filter_type;
#ifdef CONFIG_RTOS_IDUMP_FORCE
		bitmap_copy(idump_mm->sig_force, rtos_mm_current->idump.sig_force, IDUMP_SIG_NR);
#endif
	} else {
		idump_mm->dump_filter_type = 1;
		idump_mm->stacksize = 0;
#ifdef CONFIG_RTOS_IDUMP_FORCE
		bitmap_zero(idump_mm->sig_force, IDUMP_SIG_NR);
#endif
	}
	return;
}

void get_rtos_task_stack(unsigned long clone_flags, unsigned long stack_start,
		struct task_struct *p)
{
	struct rtos_task_struct *rtos_task_p = task_to_rtos_task(p);
	struct rtos_task_struct *rtos_task_current = NULL;

	if (stack_start) {
		rtos_task_p->idump.stack_start = stack_start;
	} else {
		rtos_task_current = task_to_rtos_task(current);
		rtos_task_p->idump.stack_start = rtos_task_current->idump.stack_start;
	}
}

unsigned long get_rtos_task_stack_start(struct task_struct *task)
{
	struct rtos_task_struct *rtos_task = task_to_rtos_task(task);
	return rtos_task->idump.stack_start;
}


#endif
